package client.Game;

import java.io.ObjectInputStream;
import java.io.PrintWriter;

import Server.Game.Questions.Answer;
import Server.Game.Questions.Question;
import Server.Game.Questions.XMLReader;

import client.GUI.ClientGUI;
import client.GUI.ErrorGui;
import client.GUI.lobbyGUI;

import shared.Player.Player;

public class Lobby extends Thread {
	ObjectInputStream netIn;
	PrintWriter netOut;
	String name;
	boolean start = false;
	Player player, opponent;
	Question question = new Question();
	lobbyGUI gui;

	public Lobby(String name, ObjectInputStream netIn, PrintWriter netOut){
		this.netIn = netIn;
		this.netOut = netOut;
		this.name = name;
		gui = new lobbyGUI();
		new Builder(netIn, name, this);
		start();
	}
	
	public void setGame() {
		start = true;
	}
	
	public void setPlayer(Player p) {
		player = p;
	}

	public void setOpp(Player p) {
		opponent = p;
	}


	public void run() {
		while (true) {
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				new ErrorGui("Sleep katkestati!");
				break;
			}
			if (start) {
				gui.dispose();
				new ClientGUI(player, opponent, netIn, netOut);
				break;
			}else{
				continue;
			}
		}
		
	}
}
